package com.edu.ad.mapper;

import com.edu.api.entity.ad.PromotionAd;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.edu.api.entity.common.Pageable;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Entity com.edu.api.entity.ad.PromotionAd
 */
@Repository
public interface PromotionAdMapper extends BaseMapper<PromotionAd> {

    /**
     * 获取对应广告位广告
     * @param spaceId
     * @return
     */
    @Select("select * from promotion_space ps join promotion_ad pa on ps.id = pa.space_id where ps.id = 1 and ps.is_del = 0 and pa.start_time < now() and pa.end_time > NOW() and pa.`status` = 1 order by pa.priority asc")
    List<PromotionAd> getAdsBySpaceId(int spaceId);

    /**
     * 条件查询广告
     * @param pageable
     * @param ad
     * @return
     */
    List<PromotionAd> getAllAd(@Param("pageable") Pageable pageable, @Param("ad") PromotionAd ad);

    /**
     * 添加广告
     * @param ad
     * @return
     */
    Long saveAd(@Param("ad") PromotionAd ad);

    /**
     * 通过id批量删除
     * @param ids
     * @return
     */
    Long deleteAdByIds(@Param("ids")List ids);

    /**
     * 通过显示中的广告ids查询广告位
     * @param ids
     * @return
     */
    List<Integer> getSpaceByAdIds(@Param("ids") List ids);

}




